﻿using Idte.Application.Core;
using Idte.Application.Core.Actor;
using Idte.Application.Core.Navigation;
using Idte.Core.Infrastructure.Repository;
using System;
using System.Data.Entity;

namespace Driver
{
    public class DriverContext : CodeFirstDbContext
    {
        private static DriverContext instance = null;
        public DriverContext()
            : base("CoreDb")
        {
            //Database.SetInitializer(new CoreDataInitializer());
            Database.SetInitializer(new DropCreateDatabaseAlways<DriverContext>());
        }

        public static DriverContext Instance
        {
            get
            {
                instance = instance ?? new DriverContext();
                return instance;
            }
        }
    }
    public class CoreDataInitializer : DropCreateDatabaseAlways<DriverContext>
    {
        protected override void Seed(DriverContext context)
        {
           try
            {
                //AddAppModel(context);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }

        }
       
        private void AddAppModel(DriverContext context)
        {
            //ApplicationModel model = new ApplicationModel();

            //model.Title = "KTC";
            //AppContext appContext = new AppContext();
            
            //Menu menu1 = new Menu() { Name = "admin" };
            ////appContext.Menu.Add(menu1);
            //model.Contexts.Add(appContext);
            ////model.Menu.Add(menu1);

            //Menu userMenu = new Menu() { Name = "user" };
            //userMenu.Type = MenuType.ContextMenu;
            //userMenu.Items.Add(new MenuItem() { Title = "New User", Action = "/Admin/User/Create" });
            ////appContext.Menu.Add(userMenu);

            //MenuItem item1 = new MenuItem() { Title = "System Settings" };
            //MenuItem userMgmt = new MenuItem() { Title = "User Management " };
            //userMgmt.Items.Add(new MenuItem() { Title = "Users", SubMenuId = "user" });
            //userMgmt.Items.Add(new MenuItem() { Title = "Roles and Permission" });
            //item1.Items.Add(userMgmt);
            //MenuItem item2 = new MenuItem() { Title = "Audit Frameworks" };
            //MenuItem item3 = new MenuItem() { Title = "Companies" };
            //menu1.Items.Add(item2);
            //menu1.Items.Add(item1);
            //menu1.Items.Add(item3);

            //context.Set<ApplicationModel>().Add(model);
            //context.SaveChanges();
        }
    }
}
